<?php

/**
 * This is the model class for table "ref_bank".
 *
 * The followings are the available columns in table 'ref_bank':
 * @property string $bank_id
 * @property string $bank_name
 * @property string $bank_logo
 * @property integer $bank_adm_fee
 * @property string $bank_is_active
 *
 * The followings are the available model relations:
 * @property SiteBankAccount[] $siteBankAccounts
 * @property SysBonusTransfer[] $sysBonusTransfers
 */
class ref_bank extends CActiveRecord {

    /**
     * Returns the static model of the specified AR class.
     * @return ref_bank the static model class
     */
    public static function model($className=__CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'ref_bank';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('bank_name', 'required'),
            array('bank_adm_fee', 'numerical', 'integerOnly' => true),
            array('bank_name', 'length', 'max' => 100),
            array('bank_logo', 'length', 'max' => 255),
            array('bank_is_active', 'length', 'max' => 1),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('bank_id, bank_name, bank_logo, bank_adm_fee, bank_is_active', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'rel_bank_to_bank_account' => array(self::HAS_MANY, 'site_bank_account', 'bank_account_bank_id'),
            'rel_bank_to_bonus_transfer' => array(self::HAS_MANY, 'sys_bonus_transfer', 'bonus_transfer_bank_id'),
            'rel_bank_to_sys_member'=>array(self::HAS_ONE,'sys_member','member_bank_id'),
	);
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'bank_id' => 'Bank',
            'bank_name' => 'Bank Name',
            'bank_logo' => 'Bank Logo',
            'bank_adm_fee' => 'Administration Fee',
            'bank_is_active' => 'Is Active',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('bank_id', $this->bank_id, true);
        $criteria->compare('bank_name', $this->bank_name, true);
        $criteria->compare('bank_logo', $this->bank_logo, true);
        $criteria->compare('bank_adm_fee', $this->bank_adm_fee);
        $criteria->compare('bank_is_active', $this->bank_is_active, true);

        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
        ));
    }

}
